package com.bjpowernode.services.impls;

import com.bjpowernode.constants.Constant;
import com.bjpowernode.entities.TActivityRemark;
import com.bjpowernode.mappers.TActivityRemarkMapper;
import com.bjpowernode.querys.ActivityRemarkQuery;
import com.bjpowernode.services.ActivityRemarkService;
import com.bjpowernode.utils.LoginInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityRemarkServiceImpl implements ActivityRemarkService {
    @Resource
    private TActivityRemarkMapper tActivityRemarkMapper;

    @Override
    public int saveActivityRemark(ActivityRemarkQuery activityRemarkQuery) {
        TActivityRemark tActivityRemark = new TActivityRemark();
        BeanUtils.copyProperties(activityRemarkQuery, tActivityRemark);
        tActivityRemark.setCreateTime(new Date());
        tActivityRemark.setCreateBy(LoginInfoUtil.getCurrentLoginUser().getId());
        return tActivityRemarkMapper.insertSelective(tActivityRemark);
    }

    @Override
    public PageInfo<TActivityRemark> getActivityRemarksByPage(Integer current, Integer activityId) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TActivityRemark> tActivityRemarkList = tActivityRemarkMapper.selectByPage(activityId);
        return new PageInfo<>(tActivityRemarkList);
    }
}